package com.example.admin.goodnews.fragment.QingSongYiXia;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.admin.goodnews.R;
import com.example.admin.goodnews.adapter.FragmentAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 轻松一下页面
 * Created by admin on 2016/10/14.
 */

public class QingSongYiXiaFragment extends Fragment {
    private ViewPager viewpager_qingsongyixia;// 加载内容的容器
    private TabLayout tablayout_qingsongyixia;//
    private List<String> tablists;// tab标签
    private List<Fragment> fragmentlists;// 页卡
    private FragmentAdapter fragmentAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_qingsongyixia, null);

        viewpager_qingsongyixia = (ViewPager) view.findViewById(R.id.viewpager_qingsongyixia);
        tablayout_qingsongyixia = (TabLayout) view.findViewById(R.id.tablayout_qingsongyixia);

        initData();
        return view;
    }

    private void initData() {
        tablists = new ArrayList<>();
        tablists.add("段子");
        tablists.add("图片");
        tablists.add("视频");
        fragmentlists = new ArrayList<>();
        fragmentlists.add(new DuanZiFragment());
        fragmentlists.add(new TuPianFragment());
        fragmentlists.add(new ShiPinFragment());

        fragmentAdapter = new FragmentAdapter(getActivity().getSupportFragmentManager(), tablists, fragmentlists);
        viewpager_qingsongyixia.setAdapter(fragmentAdapter);
        tablayout_qingsongyixia.setupWithViewPager(viewpager_qingsongyixia);
    }

}
